import * as url from '../../../http/api'
import axios from 'axios'
import http from '../../../http/http'

const state = {
    invoiveName: 'invoiceSt',
    number: '',          //会员号
    money: 0,           //会员余额
    mainId:'',
    seatsId: '',         //餐桌号
    totalPrice: 0,      //消费金额
    detailList: [],      //菜单详情
    payType: '',          //支付方式
}
const mutations = {
    selectVip(state, obj) {
        state.number = obj.number;
        state.money = obj.money;

    },
    choosePayType(state, type) {
        state.payType = type;
    },
    invoTableSelectSt(state, obj) {
        state.seatsId = obj.seatsId;
        state.mainId = obj.mainId;
        state.totalPrice = obj.totalPrice;
        state.detailList = obj.detailList;
    },
    invoClearDataMutation(state){
        state.seatsId='';
        state.number='';
        state.money=0;
        state.money='';
        state.totalPrice=0;
        state.detailList=[];
    },
    frontAddMoneyCommit(state,obj){
        state.money=obj.money
        console.log(state.money);
    },
}
const actions = {
    selectVip({commit}, obj) {
        // console.log(obj);
        return http({
            url: url.memberSelect,
            method: 'post',
            data: {
                number: obj.number,
            },
        }).then(respData => {
            // console.log(respData);
            if (respData.data.code === 200) {
                // console.log(respData.data);

                commit('selectVip', respData.data);
            }
            return respData.data
        }).catch(err => {
            console.log(err);
        })
    },
    invoTableSelectSt({commit}, obj) {
        // console.log(obj);
        return http({
            url: url.memberSelectOrder,
            method: 'post',
            data: {
                // mainId: obj.mainId,
                // mainId: 1,
                diningOrderMainId: obj.seatsId,
            },
        }).then(respData => {
            console.log(respData);
            // console.log(obj);
            if (respData.data.code === 200) {
                respData.data.mainId=obj.seatsId
                commit('invoTableSelectSt', respData.data);
            }
            return respData.data
        }).catch(err => {
            console.log(err);
        })
    },
    tableSelectSt({commit}, obj) {
        console.log('tableSelectSt');
        return http({
            url: url.tableSelectOrderMoney,
            method: 'post',
            data: {

                // mainId: 1,
                number: obj.seatsId,

            },
        }).then(respData => {
            console.log(respData);
            // console.log(obj);
            if (respData.data.Code === 200) {
                commit('invoTableSelectSt', respData.data);
            }
            return respData.data
        }).catch(err => {
            console.log(err);
        })
    },
    invoBuyOrderSt({commit}, obj) {
        // console.log(obj);
        return http({
            url: url.memberSettlementOrder,
            method: 'post',
            data: {
                mainId:obj.mainId,
                totalPrice: obj.totalPrice,
                number: obj.number,
                payType: obj.payType,
                money: obj.money,
            },
        }).then(respData => {
            console.log(respData);
            if (respData.data.Status === 'success') {
                commit('invoTableSelectSt', respData);
            }
            return respData.data
        }).catch(err => {
            console.log(err);
        })
    },
    choosePayType({commit}, type) {
        commit('choosePayType', Number(type));
    },
    buyOrderSt({commit}, obj) {
        // console.log(obj);
        return http({
            url: url.tableSettlementOrder,
            method: 'post',
            data: {
                totalPrice: obj.totalPrice,
                payType: obj.payType,
                mainId: obj.mainId,
            },
        }).then(respData => {
            console.log(respData);
            if (respData.data.Status === 'success') {
                commit('invoTableSelectSt', respData.data);
            }
            return respData.data
        }).catch(err => {
            console.log(err);
        })
    },
    invoClearDataAct({commit}, obj) {
        commit('invoClearDataMutation');
    },
    frontAddMoneyCommit({commit}, obj) {
        console.log('frontAddMoneyCommit');
        return http({
            url: url.memberTopUp,
            method: 'post',
            data: obj,
        }).then(respData => {
            console.log(respData.data);
            if (respData.data.code === 200) {
                commit('frontAddMoneyCommit', respData.data);
            }
            return respData.data
        }).catch(err => {
            console.log(err);
        })
    },

}

export default {
    state,
    actions,
    mutations,

}
